package com.kanesoft.android.gdx.actors.fight;

import com.badlogic.gdx.math.Vector2;
import com.kanesoft.android.gdx.widgets.sprites.SpriteInfo;

public class FighterHittenInTheAir extends FightActorStateMachine {

    private FightActorObject fightActor;
    private boolean alreadyUpdated;

    public FighterHittenInTheAir(SpriteInfo stateSpriteInfo, FightActorObject actor) {
        super(stateSpriteInfo, actor);
        fightActor = actor;
    }

    @Override
    public boolean OnEnter() {

        alreadyUpdated = false;

        actorSprite.setAnimationInLoop(true);
        actorSprite.setSpriteInfo(stateSpriteInfo);

        return true;
    }

    @Override
    public boolean OnUpdate() {
        boolean fallingReturn = fightActor.fallingKickState.OnUpdate();

         if (alreadyUpdated) return fallingReturn;
        alreadyUpdated = true;
        fightActor.decreseLifePower(5);

        fightActor.getSensorFixture().setFriction(0.2f);

        Vector2 objPosition = fightActor.getActorBody().getPosition();

        if (fightActor.getHorizontalFlip() == false) fightActor.getActorBody().applyLinearImpulse(
                -fightActor.getHitAceleration(), 0, objPosition.x, objPosition.y);
        if (fightActor.getHorizontalFlip() == true) fightActor.getActorBody().applyLinearImpulse(
                fightActor.getHitAceleration(), 0, objPosition.x, objPosition.y); 

        return fallingReturn; 
    }

    @Override
    public String getStateName() {
        return "HittenInTheAir";
    }

}
